/*     */ package com.zimbra.qa.unittest;
/*     */ 
/*     */ import com.zimbra.client.ZMailbox;
/*     */ import com.zimbra.common.account.Key.AccountBy;
/*     */ import com.zimbra.common.mailbox.ContactConstants;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.ByteUtil;
/*     */ import com.zimbra.common.util.CliUtil;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.Log.Level;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.ldap.entry.LdapAccount;
/*     */ import com.zimbra.cs.mailbox.Contact;
/*     */ import com.zimbra.cs.mailbox.ContactGroup;
/*     */ import com.zimbra.cs.mailbox.ContactGroup.ContactRefMember;
/*     */ import com.zimbra.cs.mailbox.ContactGroup.GalRefMember;
/*     */ import com.zimbra.cs.mailbox.ContactGroup.InlineMember;
/*     */ import com.zimbra.cs.mailbox.ContactGroup.Member;
/*     */ import com.zimbra.cs.mailbox.ContactGroup.Member.Type;
/*     */ import com.zimbra.cs.mailbox.Mailbox;
/*     */ import com.zimbra.cs.mailbox.MailboxManager;
/*     */ import com.zimbra.cs.mailbox.OperationContext;
/*     */ import com.zimbra.cs.mime.ParsedContact;
/*     */ import com.zimbra.cs.util.Zimbra;
/*     */ import java.io.ByteArrayInputStream;
/*     */ import java.io.ByteArrayOutputStream;
/*     */ import java.io.PrintStream;
/*     */ import java.util.HashMap;
/*     */ import java.util.Iterator;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.zip.ZipEntry;
/*     */ import java.util.zip.ZipInputStream;
/*     */ import org.junit.Assert;
/*     */ import org.junit.BeforeClass;
/*     */ import org.junit.Ignore;
/*     */ import org.junit.Test;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestContactGroup
/*     */ {
/*     */   private static final String CONTACT_REF_VALUE = "736ae588-ae90-4427-a3de-6451e47e0857:257";
/*     */   private static final String GAL_REF_VALUE = "uid=user1,ou=people,dc=zimbra,dc=com";
/*     */   private static final String INLINE_VALUE = "user@test.com";
/*     */   
/*     */   private static class MemberData
/*     */   {
/*     */     private ContactGroup.Member.Type type;
/*     */     private String value;
/*     */     
/*     */     private MemberData(ContactGroup.Member.Type type, String value)
/*     */     {
/*  70 */       this.type = type;
/*  71 */       this.value = value;
/*     */     }
/*     */   }
/*     */   
/*     */   private ContactGroup createContactGroup(MemberData[] members) throws Exception {
/*  76 */     ContactGroup contactGroup = ContactGroup.init();
/*  77 */     for (MemberData member : members) {
/*  78 */       contactGroup.addMember(member.type, member.value);
/*     */     }
/*  80 */     return reEncode(contactGroup);
/*     */   }
/*     */   
/*     */   private ContactGroup reEncode(ContactGroup contactGroup) throws Exception
/*     */   {
/*  85 */     String encoded = contactGroup.encode();
/*  86 */     return ContactGroup.init(encoded);
/*     */   }
/*     */   
/*     */   @BeforeClass
/*     */   public static void init() throws Exception {
/*  91 */     Zimbra.startupCLI();
/*  92 */     CliUtil.toolSetup();
/*  93 */     ZimbraLog.contact.setLevel(Log.Level.debug);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   @Test
/*     */   public void deleteAllMembers()
/*     */     throws Exception
/*     */   {
/* 104 */     ContactGroup contactGroup = createContactGroup(new MemberData[] { new MemberData(ContactGroup.Member.Type.CONTACT_REF, "736ae588-ae90-4427-a3de-6451e47e0857:257", null), new MemberData(ContactGroup.Member.Type.GAL_REF, "uid=user1,ou=people,dc=zimbra,dc=com", null), new MemberData(ContactGroup.Member.Type.INLINE, "user@test.com", null) });
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 109 */     contactGroup.removeAllMembers();
/*     */     
/* 111 */     contactGroup = reEncode(contactGroup);
/*     */     
/* 113 */     List<ContactGroup.Member> members = contactGroup.getMembers();
/* 114 */     Assert.assertEquals(0L, members.size());
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void getMembers() throws Exception {
/* 119 */     ContactGroup contactGroup = createContactGroup(new MemberData[] { new MemberData(ContactGroup.Member.Type.CONTACT_REF, "736ae588-ae90-4427-a3de-6451e47e0857:257", null), new MemberData(ContactGroup.Member.Type.GAL_REF, "uid=user1,ou=people,dc=zimbra,dc=com", null), new MemberData(ContactGroup.Member.Type.INLINE, "user@test.com", null) });
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 124 */     List<ContactGroup.Member> members = contactGroup.getMembers();
/* 125 */     Assert.assertEquals(3L, members.size());
/* 126 */     Assert.assertTrue(members.get(0) instanceof ContactGroup.ContactRefMember);
/* 127 */     Assert.assertEquals("736ae588-ae90-4427-a3de-6451e47e0857:257", ((ContactGroup.Member)members.get(0)).getValue());
/* 128 */     Assert.assertTrue(members.get(1) instanceof ContactGroup.GalRefMember);
/* 129 */     Assert.assertEquals("uid=user1,ou=people,dc=zimbra,dc=com", ((ContactGroup.Member)members.get(1)).getValue());
/* 130 */     Assert.assertTrue(members.get(2) instanceof ContactGroup.InlineMember);
/* 131 */     Assert.assertEquals("user@test.com", ((ContactGroup.Member)members.get(2)).getValue());
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void addMember() throws Exception {
/* 136 */     ContactGroup contactGroup = createContactGroup(new MemberData[] { new MemberData(ContactGroup.Member.Type.CONTACT_REF, "736ae588-ae90-4427-a3de-6451e47e0857:257", null), new MemberData(ContactGroup.Member.Type.GAL_REF, "uid=user1,ou=people,dc=zimbra,dc=com", null), new MemberData(ContactGroup.Member.Type.INLINE, "user@test.com", null) });
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 141 */     MemberData memberToAdd = new MemberData(ContactGroup.Member.Type.INLINE, "added", null);
/* 142 */     ContactGroup.Member addedMember = contactGroup.addMember(memberToAdd.type, memberToAdd.value);
/*     */     
/* 144 */     contactGroup = reEncode(contactGroup);
/*     */     
/* 146 */     List<ContactGroup.Member> members = contactGroup.getMembers();
/* 147 */     Assert.assertEquals(4L, members.size());
/*     */     
/* 149 */     ContactGroup.Member newMember = (ContactGroup.Member)members.get(3);
/* 150 */     Assert.assertEquals(memberToAdd.type, newMember.getType());
/* 151 */     Assert.assertEquals(memberToAdd.value, newMember.getValue());
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void addDupMember() throws Exception {
/* 156 */     ContactGroup contactGroup = createContactGroup(new MemberData[] { new MemberData(ContactGroup.Member.Type.CONTACT_REF, "736ae588-ae90-4427-a3de-6451e47e0857:257", null), new MemberData(ContactGroup.Member.Type.GAL_REF, "uid=user1,ou=people,dc=zimbra,dc=com", null), new MemberData(ContactGroup.Member.Type.INLINE, "user@test.com", null) });
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 161 */     MemberData memberToAdd = new MemberData(ContactGroup.Member.Type.GAL_REF, "uid=user1,ou=people,dc=zimbra,dc=com", null);
/*     */     
/* 163 */     boolean caughtException = false;
/*     */     try {
/* 165 */       contactGroup.addMember(memberToAdd.type, memberToAdd.value);
/*     */     } catch (ServiceException e) {
/* 167 */       if (e.getMessage().startsWith("invalid request: member already exists:")) {
/* 168 */         caughtException = true;
/*     */       }
/*     */     }
/*     */     
/* 172 */     Assert.assertTrue(caughtException);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void removeMember() throws Exception {
/* 177 */     ContactGroup contactGroup = createContactGroup(new MemberData[] { new MemberData(ContactGroup.Member.Type.CONTACT_REF, "736ae588-ae90-4427-a3de-6451e47e0857:257", null), new MemberData(ContactGroup.Member.Type.GAL_REF, "uid=user1,ou=people,dc=zimbra,dc=com", null), new MemberData(ContactGroup.Member.Type.INLINE, "user@test.com", null) });
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 182 */     ContactGroup.Member memberToRemove = (ContactGroup.Member)contactGroup.getMembers().get(0);
/* 183 */     contactGroup.removeMember(memberToRemove.getType(), memberToRemove.getValue());
/*     */     
/* 185 */     contactGroup = reEncode(contactGroup);
/*     */     
/* 187 */     List<ContactGroup.Member> members = contactGroup.getMembers();
/* 188 */     Assert.assertEquals(2L, members.size());
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void removeNonExistingMember() throws Exception {
/* 193 */     ContactGroup contactGroup = createContactGroup(new MemberData[] { new MemberData(ContactGroup.Member.Type.CONTACT_REF, "736ae588-ae90-4427-a3de-6451e47e0857:257", null), new MemberData(ContactGroup.Member.Type.GAL_REF, "uid=user1,ou=people,dc=zimbra,dc=com", null), new MemberData(ContactGroup.Member.Type.INLINE, "user@test.com", null) });
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 198 */     boolean caughtException = false;
/*     */     try {
/* 200 */       contactGroup.removeMember(ContactGroup.Member.Type.INLINE, "not there");
/*     */     } catch (ServiceException e) {
/* 202 */       if (e.getMessage().startsWith("invalid request: no such member:")) {
/* 203 */         caughtException = true;
/*     */       }
/*     */     }
/* 206 */     Assert.assertTrue(caughtException);
/*     */     
/*     */ 
/* 209 */     contactGroup = reEncode(contactGroup);
/*     */     
/* 211 */     List<ContactGroup.Member> members = contactGroup.getMembers();
/* 212 */     Assert.assertEquals(3L, members.size());
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void insertOrder() throws Exception
/*     */   {
/* 218 */     int NUM_MEMBERS = 5;
/*     */     
/* 220 */     ContactGroup contactGroup = createContactGroup(new MemberData[0]);
/*     */     
/* 222 */     for (int i = 1; i <= NUM_MEMBERS; i++) {
/* 223 */       MemberData memberData = new MemberData(ContactGroup.Member.Type.INLINE, "" + i, null);
/* 224 */       contactGroup.addMember(memberData.type, memberData.value);
/*     */     }
/*     */     
/* 227 */     contactGroup = reEncode(contactGroup);
/*     */     
/* 229 */     List<ContactGroup.Member> members = contactGroup.getMembers();
/*     */     
/* 231 */     ContactGroup.Member firstMember = (ContactGroup.Member)members.get(0);
/*     */     
/*     */ 
/* 234 */     contactGroup.removeMember(firstMember.getType(), firstMember.getValue());
/*     */     
/*     */ 
/* 237 */     contactGroup.addMember(firstMember.getType(), firstMember.getValue());
/*     */     
/* 239 */     contactGroup = reEncode(contactGroup);
/* 240 */     members = contactGroup.getMembers();
/*     */     
/*     */ 
/* 243 */     for (int i = 0; i < NUM_MEMBERS - 1; i++) {
/* 244 */       ContactGroup.Member member = (ContactGroup.Member)members.get(i);
/* 245 */       Assert.assertEquals(ContactGroup.Member.Type.INLINE, member.getType());
/* 246 */       Assert.assertEquals("" + (i + 2), member.getValue());
/*     */     }
/*     */     
/* 249 */     ContactGroup.Member lastMember = (ContactGroup.Member)members.get(NUM_MEMBERS - 1);
/* 250 */     Assert.assertEquals(firstMember.getType(), lastMember.getType());
/* 251 */     Assert.assertEquals(firstMember.getValue(), lastMember.getValue());
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void unmodifiableList() throws Exception {
/* 256 */     ContactGroup contactGroup = createContactGroup(new MemberData[] { new MemberData(ContactGroup.Member.Type.CONTACT_REF, "736ae588-ae90-4427-a3de-6451e47e0857:257", null), new MemberData(ContactGroup.Member.Type.GAL_REF, "uid=user1,ou=people,dc=zimbra,dc=com", null), new MemberData(ContactGroup.Member.Type.INLINE, "user@test.com", null) });
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 261 */     boolean caughtException = false;
/*     */     try {
/* 263 */       members = contactGroup.getMembers();
/* 264 */       for (ContactGroup.Member member : members)
/* 265 */         members.remove(member);
/*     */     } catch (UnsupportedOperationException e) {
/*     */       List<ContactGroup.Member> members;
/* 268 */       caughtException = true;
/*     */     }
/* 270 */     Assert.assertTrue(caughtException);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void membersIterator() throws Exception {
/* 275 */     ContactGroup contactGroup = createContactGroup(new MemberData[] { new MemberData(ContactGroup.Member.Type.CONTACT_REF, "736ae588-ae90-4427-a3de-6451e47e0857:257", null), new MemberData(ContactGroup.Member.Type.GAL_REF, "uid=user1,ou=people,dc=zimbra,dc=com", null), new MemberData(ContactGroup.Member.Type.INLINE, "user@test.com", null) });
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 280 */     boolean caughtException = false;
/*     */     try {
/* 282 */       for (iter = contactGroup.getMembers().iterator(); iter.hasNext();) {
/* 283 */         ContactGroup.Member member = (ContactGroup.Member)iter.next();
/*     */         
/* 285 */         if ((member.getType() == ContactGroup.Member.Type.GAL_REF) || (member.getType() == ContactGroup.Member.Type.INLINE))
/* 286 */           iter.remove();
/*     */       }
/*     */     } catch (UnsupportedOperationException e) {
/*     */       Iterator<ContactGroup.Member> iter;
/* 290 */       caughtException = true;
/*     */     }
/* 292 */     Assert.assertTrue(caughtException);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void derefContact() throws Exception {
/* 297 */     Account account = Provisioning.getInstance().get(Key.AccountBy.name, TestUtil.getAddress("user1"));
/* 298 */     Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
/* 299 */     OperationContext octxt = null;
/*     */     
/* 301 */     Map<String, Object> fields = new HashMap();
/* 302 */     fields.put(ContactConstants.A_fileAs, Integer.valueOf(2));
/* 303 */     fields.put(ContactConstants.A_firstName, "test");
/* 304 */     fields.put(ContactConstants.A_email, "test1@zimbra.com");
/* 305 */     fields.put(ContactConstants.A_workEmail1, "test2@zimbra.com");
/* 306 */     Contact contact = mbox.createContact(octxt, new ParsedContact(fields), 7, null);
/*     */     
/* 308 */     ContactGroup contactGroup = createContactGroup(new MemberData[] { new MemberData(ContactGroup.Member.Type.CONTACT_REF, "" + contact.getId(), null), new MemberData(ContactGroup.Member.Type.INLINE, "aaa@test.com", null), new MemberData(ContactGroup.Member.Type.INLINE, "zzz@test.com", null) });
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 313 */     contactGroup.derefAllMembers(mbox, octxt);
/*     */     
/* 315 */     boolean gotContactRefMember = false;
/* 316 */     String prevMemberKey = null;
/* 317 */     for (ContactGroup.Member member : contactGroup.getDerefedMembers()) {
/* 318 */       String memberKey = member.getDerefedKey();
/* 319 */       if (prevMemberKey != null) {
/* 320 */         Assert.assertTrue(prevMemberKey.compareTo(memberKey) < 0);
/*     */       }
/* 322 */       prevMemberKey = memberKey;
/*     */       
/* 324 */       ContactGroup.Member.Type type = member.getType();
/* 325 */       if (type == ContactGroup.Member.Type.CONTACT_REF) {
/* 326 */         Assert.assertEquals("test", memberKey);
/* 327 */         gotContactRefMember = true;
/*     */       }
/*     */     }
/*     */     
/*     */ 
/* 332 */     List<String> emailAddrs = contactGroup.getEmailAddresses(false, mbox, octxt, false);
/* 333 */     Assert.assertEquals(4L, emailAddrs.size());
/* 334 */     Assert.assertTrue(emailAddrs.contains("test1@zimbra.com"));
/* 335 */     Assert.assertTrue(emailAddrs.contains("test2@zimbra.com"));
/* 336 */     Assert.assertTrue(emailAddrs.contains("aaa@test.com"));
/* 337 */     Assert.assertTrue(emailAddrs.contains("zzz@test.com"));
/*     */     
/* 339 */     Assert.assertTrue(gotContactRefMember);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void derefGal() throws Exception {
/* 344 */     Account account = Provisioning.getInstance().get(Key.AccountBy.name, TestUtil.getAddress("user1"));
/* 345 */     Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
/* 346 */     OperationContext octxt = null;
/*     */     
/* 348 */     Account galMember = Provisioning.getInstance().get(Key.AccountBy.name, TestUtil.getAddress("user2"));
/* 349 */     LdapAccount ldapAccount = (LdapAccount)galMember;
/* 350 */     String dn = ldapAccount.getDN();
/* 351 */     String email = galMember.getName();
/*     */     
/* 353 */     ContactGroup contactGroup = createContactGroup(new MemberData[] { new MemberData(ContactGroup.Member.Type.GAL_REF, dn, null), new MemberData(ContactGroup.Member.Type.INLINE, "aaa@test.com", null), new MemberData(ContactGroup.Member.Type.INLINE, "zzz@test.com", null) });
/*     */     
/*     */ 
/*     */ 
/*     */ 
/* 358 */     contactGroup.derefAllMembers(mbox, octxt);
/*     */     
/* 360 */     boolean gotGalRefMember = false;
/* 361 */     String prevMemberKey = null;
/* 362 */     for (ContactGroup.Member member : contactGroup.getDerefedMembers()) {
/* 363 */       String memberKey = member.getDerefedKey();
/* 364 */       if (prevMemberKey != null) {
/* 365 */         Assert.assertTrue(prevMemberKey.compareTo(memberKey) < 0);
/*     */       }
/* 367 */       prevMemberKey = memberKey;
/*     */       
/* 369 */       ContactGroup.Member.Type type = member.getType();
/* 370 */       if (type == ContactGroup.Member.Type.GAL_REF) {
/* 371 */         Assert.assertEquals(email, memberKey);
/* 372 */         gotGalRefMember = true;
/*     */       }
/*     */     }
/*     */     
/*     */ 
/* 377 */     List<String> emailAddrs = contactGroup.getEmailAddresses(false, mbox, octxt, false);
/* 378 */     Assert.assertEquals(3L, emailAddrs.size());
/* 379 */     Assert.assertTrue(emailAddrs.contains(email));
/* 380 */     Assert.assertTrue(emailAddrs.contains("aaa@test.com"));
/* 381 */     Assert.assertTrue(emailAddrs.contains("zzz@test.com"));
/*     */     
/* 383 */     Assert.assertTrue(gotGalRefMember);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void replaceMembersWithDlist() throws Exception {
/* 388 */     ContactGroup contactGroup = createContactGroup(new MemberData[] { new MemberData(ContactGroup.Member.Type.CONTACT_REF, "736ae588-ae90-4427-a3de-6451e47e0857:257", null), new MemberData(ContactGroup.Member.Type.GAL_REF, "uid=user1,ou=people,dc=zimbra,dc=com", null) });
/*     */     
/*     */ 
/*     */ 
/* 392 */     String dlist = "\"Ballard, Martha\" <martha34@aol.com>, \"Davidson, Ross\" <rossd@example.zimbra.com>, user1@test.com";
/* 393 */     contactGroup.migrateFromDlist(dlist);
/*     */     
/* 395 */     contactGroup = reEncode(contactGroup);
/*     */     
/* 397 */     List<ContactGroup.Member> members = contactGroup.getMembers();
/* 398 */     Assert.assertEquals(3L, members.size());
/*     */     
/* 400 */     ContactGroup.Member member = (ContactGroup.Member)members.get(0);
/* 401 */     Assert.assertEquals(ContactGroup.Member.Type.INLINE, member.getType());
/* 402 */     Assert.assertEquals("\"Ballard, Martha\" <martha34@aol.com>", member.getValue());
/*     */     
/* 404 */     member = (ContactGroup.Member)members.get(1);
/* 405 */     Assert.assertEquals(ContactGroup.Member.Type.INLINE, member.getType());
/* 406 */     Assert.assertEquals("\"Davidson, Ross\" <rossd@example.zimbra.com>", member.getValue());
/*     */     
/* 408 */     member = (ContactGroup.Member)members.get(2);
/* 409 */     Assert.assertEquals(ContactGroup.Member.Type.INLINE, member.getType());
/* 410 */     Assert.assertEquals("user1@test.com", member.getValue());
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void returnMembersAsDlist() throws Exception {
/* 415 */     Account account = Provisioning.getInstance().get(Key.AccountBy.name, TestUtil.getAddress("user1"));
/* 416 */     Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
/* 417 */     OperationContext octxt = null;
/*     */     
/* 419 */     Map<String, Object> fields = new HashMap();
/* 420 */     fields.put(ContactConstants.A_fileAs, Integer.valueOf(2));
/* 421 */     fields.put(ContactConstants.A_firstName, "test");
/* 422 */     fields.put(ContactConstants.A_email, "test1@zimbra.com");
/* 423 */     fields.put(ContactConstants.A_workEmail1, "test2@zimbra.com");
/* 424 */     Contact contact = mbox.createContact(octxt, new ParsedContact(fields), 7, null);
/*     */     
/* 426 */     Account galMember = Provisioning.getInstance().get(Key.AccountBy.name, TestUtil.getAddress("user2"));
/* 427 */     LdapAccount ldapAccount = (LdapAccount)galMember;
/* 428 */     String dn = ldapAccount.getDN();
/* 429 */     String galEntryEmail = galMember.getName();
/*     */     
/* 431 */     ContactGroup contactGroup = createContactGroup(new MemberData[] { new MemberData(ContactGroup.Member.Type.CONTACT_REF, "" + contact.getId(), null), new MemberData(ContactGroup.Member.Type.GAL_REF, dn, null), new MemberData(ContactGroup.Member.Type.INLINE, "aaa@test.com", null), new MemberData(ContactGroup.Member.Type.INLINE, "zzz@test.com", null) });
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 437 */     contactGroup.derefAllMembers(mbox, octxt);
/* 438 */     for (ContactGroup.Member member : contactGroup.getDerefedMembers()) {
/* 439 */       String memberKey = member.getDerefedKey();
/* 440 */       System.out.println(memberKey);
/*     */     }
/*     */     
/* 443 */     String dlist = contactGroup.migrateToDlist(mbox, octxt);
/*     */     
/*     */ 
/* 446 */     Assert.assertEquals("test1@zimbra.com, test2@zimbra.com, " + galEntryEmail + ", aaa@test.com, zzz@test.com", dlist);
/*     */   }
/*     */   
/*     */   @Test
/*     */   @Ignore
/*     */   public void zimbraDelimittedFields() throws Exception {
/* 452 */     Account acct = Provisioning.getInstance().get(Key.AccountBy.name, TestUtil.getAddress("user1"));
/*     */     
/* 454 */     String relativePath = "/Contacts?fmt=cf&t=2&all";
/*     */     
/* 456 */     ZMailbox mbox = TestUtil.getZMailbox(acct.getName());
/* 457 */     byte[] bytes = ByteUtil.getContent(mbox.getRESTResource(relativePath), 1024);
/* 458 */     String data = new String(bytes);
/*     */     
/*     */ 
/*     */ 
/* 462 */     String[] contacts = data.split("\036");
/* 463 */     for (String contact : contacts)
/*     */     {
/* 465 */       String[] fields = contact.split("\035");
/* 466 */       for (int i = 0; i < fields.length - 1; i += 2) {
/* 467 */         System.out.println(fields[i] + " = " + fields[(i + 1)]);
/*     */       }
/* 469 */       System.out.println();
/*     */     }
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void csvOldZCOClient() throws Exception {
/* 475 */     Account acct = Provisioning.getInstance().get(Key.AccountBy.name, TestUtil.getAddress("user1"));
/*     */     
/*     */ 
/*     */ 
/* 479 */     String relativePath = "/?fmt=zip&meta=1&zlv=4&list=257";
/*     */     
/* 481 */     int BUFFER = 2048;
/*     */     
/* 483 */     ZMailbox mbox = TestUtil.getZMailbox(acct.getName());
/* 484 */     ZipInputStream zin = new ZipInputStream(mbox.getRESTResource(relativePath));
/* 485 */     ZipEntry ze = null;
/* 486 */     while ((ze = zin.getNextEntry()) != null) {
/* 487 */       System.out.println("Unzipping " + ze.getName());
/*     */       
/* 489 */       byte[] data = new byte['ࠀ'];
/* 490 */       ByteArrayOutputStream os = new ByteArrayOutputStream();
/*     */       int count;
/* 492 */       while ((count = zin.read(data, 0, 2048)) != -1) {
/* 493 */         os.write(data, 0, count);
/*     */       }
/* 495 */       os.flush();
/*     */       
/* 497 */       ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
/* 498 */       byte[] bytes = ByteUtil.getContent(is, 1024);
/* 499 */       String dd = new String(bytes, "UTF-8");
/* 500 */       System.out.println(dd);
/* 501 */       is.close();
/*     */       
/* 503 */       os.close();
/*     */     }
/* 505 */     zin.close();
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/TestContactGroup.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */